<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8" />
		<title>jQuery的DOM操作-练习</title>
		<style type="text/css">
			body {
				font-size: 13px;
				line-height: 25px;
			}
			
			table {
				border-top: 1px solid #333;
				border-left: 1px solid #333;
				width: 300px;
			}
			
			td {
				border-right: 1px solid #333;
				border-bottom: 1px solid #333;
			}
			
			.center {
				text-align: center;
			}
		</style>
		<script src="jquery-3.6.0.min.js"></script>
		<script>
			function addRow() {	
				// let col2=$("<td>幸福从天而降</td> + <td>￥64.00</td>")
				// $("#row3").before(col2)
				//在row3节点前面追加
				var add= $("#row3").before(
					"<tr id=" + row1+ ">" + "<td>"+ "幸福从天而降" +"<td class='center'> " + " ￥64.00 " + " </td>" +" </tr>"
					);
			}
			function updateRow() {
				// var uRow = document.getElementById("row1");
				// //标题行设置为字体加粗、文本居中显示，背景颜色为灰色
				// uRow.setAttribute("style", "font-weight:bold;text-align:center;background-color: #cccccc;");
				$("#row1").css({
					"backgroundColor":"red",
					"fontSize":"36px",
					"height":"50px"
				})
			}
			function delRow() {
				//var dRow = document.getElementsByTagName("tr"); //访问被删除的行
				// if(dRow[2]!=null){
				// 	dRow[2].parentNode.removeChild(dRow[2]); //删除行
				// }
				$("#myTable tr").eq(1).remove();
			}
			function copyRow() {
				// var oldRow = document.getElementById("row3"); //访问复制的行
				// var newRow = oldRow.cloneNode(true); //复制指定的行及子节点
				// document.getElementById("myTable").appendChild(newRow); //在指定节点的末尾添加行
				$("#myTable").append($("tr:last").clone(true))
			}			
		</script>
	</head>
	<body>
		<h1>189000819谭君容</h1>
		<table border="0" cellspacing="0" cellpadding="0" id="myTable">
			<tr id="row1">
				<td>书名</td>
				<td>价格</td>
			</tr>
			<tr id="row2">
				<td>看得见风景的房间</td>
				<td class="center">&yen;30.00</td>
			</tr>
			<tr id="row3">
				<td>60个瞬间</td>
				<td class="center">&yen;32.00</td>
			</tr>
		</table>
		<input name="b1" type="button" value="增加一行" onclick="addRow()" />
		<input name="b2" type="button" value="删除第2行" onclick="delRow()" />
		<input name="b3" type="button" value="修改标题样式" onclick="updateRow()" />
		<input name="b4" type="button" value="复制最后一行" onclick="copyRow()" />

	</body>

</html>